﻿/*****************************************************
 * Exemplo integração CLR SQl SERVER 2005
 * Autor: Walter Vieira
 * Data: Março de 2007
******************************************************/

#region Using directives

using System;
using System.Collections.Generic;
using System.Text;
using System.Data;
using System.Data.SqlClient;



#endregion

namespace TesteSextoExemplo
{
	class Program
	{
		static void Main(string[] args)
        {
            string strConn = "Data Source=sisad_mobile\\instancia1;Initial Catalog=TesteManagedCode;User ID='sa';Password='123';";
			string strSQL = "Select vol from tabVolume";

			Volume v;

			SqlConnection cn = new SqlConnection(strConn);
			try
			{
				cn.Open();
				SqlCommand cmd = new SqlCommand(strSQL, cn);
				SqlDataReader rdr = cmd.ExecuteReader();
				if (rdr.Read())
				{
					v = (Volume)rdr.GetValue(0);
					Console.WriteLine(v.Valor+" "+v.Unidades);
				}
				rdr.Close();

                SqlCommand cmd1 = new SqlCommand("t6e", cn);
                cmd1.CommandType = CommandType.StoredProcedure;
                SqlParameter par = cmd1.Parameters.Add("@v",SqlDbType.Udt);
                par.Direction = ParameterDirection.Input;
                par.UdtTypeName = "TesteManagedCode.dbo.Volume";
                v = new Volume();
                v.Unidades = "l";
                v.Valor = 999;
                par.Value = v;
                cmd1.ExecuteNonQuery(); 
			}
			catch (Exception e)
			{
				Console.WriteLine(e.ToString());
			}
			finally
			{
				cn.Close();
			}
			Console.ReadLine();

		}
	}
}
